<?php

namespace App\Http\Requests;

class GoodsRequest extends BaseRequest
{
    protected $rules = [

    ];

    //这里我只写了部分字段，可以定义全部字段
    protected $strings_key = [
        'goods_id'=>'商品ID',
        'order_id'=>'订单ID',
    ];

    public function rules()
    {
        $function = request()->route()->getAction();
        $rules = $this->rules;
        // 根据不同的情况, 添加不同的验证规则

        if ($function['controller'] == 'App\Http\Controllers\Api\GoodsController@goods_info')
        {
            $rules=[
                'goods_id'=>'required|exists:goods,id',
            ];
        }

        if ($function['controller'] == 'App\Http\Controllers\Api\GoodsController@buy_goods')
        {
            $rules=[
                'goods_id'=>'required|exists:goods,id',
            ];
        }

        if ($function['controller'] == 'App\Http\Controllers\Api\GoodsController@pay_order')
        {
            $rules=[
                'order_id'=>'required|exists:order,id',
            ];
        }

        return $rules;

    }
}
